package mongodb;

import java.util.HashMap;
import java.util.Map;

import org.bson.Document;

import com.mongodb.client.MongoCollection;
import com.mongodb.operation.OrderBy;

public class App {
	public static void main(String[] args) {
		MongoHelper helper = MongoHelper.getInstance();

		System.out.println(helper.getAllDatabaseNames());

		System.out.println(helper.getAllCollectionNames("test"));

		MongoCollection<Document> collection = helper.getCollection("test", "foods");

		System.out.println(helper.find("test", "foods", helper.condition(MongoOperationEnum.EQ, "name", "bread")));

		System.out.println(helper.find("test", "foods", helper.condition(MongoOperationEnum.GT, "price", 3)));

		System.out.println(helper.find("test", "foods",
				helper.condition(MongoOperationEnum.OR, helper.condition(MongoOperationEnum.EQ, "name", "bread"),
						helper.condition(MongoOperationEnum.GT, "price", 3)),
				"price", OrderBy.DESC, null, null));

		Map<String, Object> upda = new HashMap<String, Object>();
		upda.put("price", 55);
		System.out.println(helper.update("test", "foods", helper.condition(MongoOperationEnum.EQ, "price", 5.5), upda));

		System.out.println(helper.delete("test", "foods", helper.condition(MongoOperationEnum.EQ, "price", 55)));

		Map<String, Object> properties = new HashMap<String, Object>();
		properties.put("id", 4);
		properties.put("name", "milk2");
		properties.put("price", 5.5);
		helper.insert("test", "foods", properties);

		System.out.println(helper.find("test", "foods", null));
	}

}
